package com.csw.compose.ui.module.component.base

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.csw.compose.theme.pagePadding
import com.csw.compose.ui.Destination
import com.csw.compose.ui.components.BodyText
import com.csw.compose.ui.components.LabelText
import com.csw.compose.ui.components.LargeSpacer
import com.csw.compose.ui.components.NormalSpacer
import com.csw.compose.ui.components.OlItem
import com.csw.compose.ui.components.PrimaryTitle
import com.csw.compose.ui.components.UlItem
import com.csw.compose.ui.module.BasePage

@Preview
@Composable
fun ProgressIndicatorPagePreview() {
    BasePage({}, "进度条（ProgressIndicator）") {
        ProgressIndicatorPage()
    }
}

class ProgressIndicatorPageData {
    companion object : Destination("ProgressIndicatorPage")
}

/**
 *[参考](https://developer.android.google.cn/develop/ui/compose/components/progress?hl=zh-cn)
 */
@Composable
fun ProgressIndicatorPage() {
    Column(
        modifier = Modifier
            .padding(horizontal = pagePadding)
            .verticalScroll(rememberScrollState())
    ) {
        PrimaryTitle("简介")
        BodyText("进度条组件，类似ProgressBar")

        LargeSpacer()
        LinearProgressIndicator(
            modifier = Modifier.fillMaxWidth().height(20.dp),
            strokeCap = StrokeCap.Butt,
            gapSize = 0.dp,
        )
        NormalSpacer()
        LinearProgressIndicator(
            modifier = Modifier.fillMaxWidth().height(20.dp),
            progress = { 0.5f },
            strokeCap = StrokeCap.Butt,
            gapSize = 0.dp,
            drawStopIndicator = {}
        )
        NormalSpacer()
        UlItem("LinearProgressIndicator")
        LabelText("线性进度指示器，颜色可通过参数进行控制")
        OlItem(1,"progress")
        LabelText("进度，若不设置该参数，则表现为不确定状态，进度条会进行无限滚动")
        OlItem(2,"strokeCap")
        LabelText("进度条绘制笔触，无（Butt），圆角（Round），矩形（Square）")
        OlItem(3,"gapSize")
        LabelText("指示器与进度条之间的间距大小")
        OlItem(4,"drawStopIndicator")
        LabelText("在进度条终点位置绘制指示器")

        LargeSpacer()
        CircularProgressIndicator(
            modifier = Modifier.size(60.dp),
            strokeWidth = 10.dp,
            strokeCap = StrokeCap.Round
        )
        NormalSpacer()
        CircularProgressIndicator(
            modifier = Modifier.size(60.dp),
            progress = { 0.5f },
            strokeWidth = 10.dp,
            strokeCap = StrokeCap.Round,
            gapSize = (-10).dp
        )
        UlItem("CircularProgressIndicator")
        LabelText("圆形进度指示器")
    }
}